<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script src="<c:url value='/static/jquery/jquery-1.9.1.min.js'/>" type="text/javascript"></script>
<script type="text/javascript" src="<c:url value='/static/themes/js/jquery.datatables.min.js'/>"></script>
<script type="text/javascript" src="<c:url value='/static/datetimepicker/js/bootstrap-datetimepicker.js'/>"charset="UTF-8"></script>
	
<title>商家账户管理</title>
</head>
<body>
	<div class="panel panel-default bk-bg-white">
		<div class="panel-body">
		<form class="form-horizontal" id="searchForm" action="#">
			<div class="row">
				<div class="form-group col-sm-4">
					<label  class="col-sm-4 control-label">商家生财ID:</label> 
					<div class="col-sm-8">
						<input type="text" class="form-control" id="businessUserId" name="businessUserId" placeholder="商家生财ID">
					</div>
				</div>
				
				<div class="form-group col-sm-4">
					<label  class="col-sm-4 control-label">商家登陆账号:</label> 
					<div class="col-sm-8">
						<input type="text" class="form-control" id="userName" name="userName"  placeholder="商家登陆账号">
					</div>
				</div>
				<div class="form-group col-sm-4">
					<label  class="col-sm-4 control-label">账号状态:</label> 
					<div class="col-sm-8">
						<select id="accountStatus" class="form-control" name="accountStatus" >
							<option value="">所有状态</option>
							<option value="0">使用中</option>
							<option value="1">已冻结</option>
						</select>
					</div>
				</div>
			</div>
			<div class="row">
				
				<div class="form-group col-sm-4">
					<label  class="col-sm-4 control-label">联系电话:</label> 
					<div class="col-sm-8">
   						<input type="text" class="form-control" id="phone" name="phone"  placeholder="联系电话">
					</div>
				</div>
				<div class="form-group col-sm-4">
					<label  class="col-sm-4 control-label">联系QQ:</label> 
					<div class="col-sm-8">
						<input type="text" class="form-control" id="qqno" name="qqno"  placeholder="联系QQ">
					</div>
				</div>
				<div class="form-group col-sm-4">
					<label  class="col-sm-4 control-label">联系微信:</label> 
					<div class="col-sm-8">
						<input type="text" class="form-control" id="wechatNo" name="wechatNo"   placeholder="联系微信">
					</div>
				</div>
			</div>
			<div class="row">
				<div class="form-group col-sm-4">
					<label  class="col-sm-4 control-label">注册时间:</label> 
					<div class="col-sm-8">
   						<input class="input-append date form_datetime form-control" id="starttime" name="starttime" readonly="readonly">
						    <span class="add-on"><i class="icon-remove"></i></span>
						    <span class="add-on"><i class="icon-calendar"></i></span>
					</div>
				</div>
				<div class="form-group col-sm-4">
					<label  class="col-sm-1 control-label">-</label>
					<div class="col-sm-8">
   						<input class="input-append date form_datetime form-control" id="endtime" name="endtime" readonly="readonly">
						    <span class="add-on"><i class="icon-remove"></i></span>
						    <span class="add-on"><i class="icon-calendar"></i></span>
					</div>
				</div>
			</div>
			<div class="form-group col-sm-12" style="padding-bottom: 15px; text-align: center;">
					<button id="search" type="button" class="btn btn-primary glyphicon glyphicon-search"> 搜索</button>
					<button id="report" type="button" class="btn btn-success glyphicon glyphicon-download"> 批量导出</button>
			</div>
		</form>	
		</div>
	</div>
	<!-- panel-body -->
	<div id="message"></div>
	<!-- panel -->
	<div class="panel panel-default">
		<div class="panel-body">
			<div class="table-responsive">
				<div id="table1_wrapper" class="dataTables_wrapper no-footer">
					<table id="table" class="display nowrap" cellspacing="0" width="100%">
						<thead>
							<tr role="row">
								<th>生财ID</th>
								<th>登陆账号</th>
								<th>注册时间</th>
								<th>联系电话</th>
								<th>QQ</th>
								<th>微信</th>
								<th>账号状态</th>
								<th></th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
		</div>
		<div id="page">
			
		</div>
	</div>

	<script type="text/javascript">
	
	
	$(function($) {
		//日期控件
		$('#starttime').datetimepicker({
			language : 'zh-CN',
			format : 'yyyy-mm-dd hh:ii', 
			autoclose : true,
			todayBtn : true,
			minuteStep : 10
		}).on('changeDate', function (ev) {
			var starttime = $(this).val();
			$('#endtime').datetimepicker('setStartDate',starttime);
            $(this).datetimepicker('hide');  
        });
		
		$('#endtime').datetimepicker({
			language : 'zh-CN',
			format : 'yyyy-mm-dd hh:ii',
			autoclose : true,
			todayBtn : true,
			minuteStep : 10
		}).on('changeDate', function (ev) {
			var time = $(this).val();
			$('#starttime').datetimepicker('setEndDate',time);
            $(this).datetimepicker('hide');  
        });
		
		function getParams(){
        	return {
            	"businessUserId": $('#businessUserId').val(),//商家生财ID
                "userName": $('#userName').val(),//商家登陆账号
                "accountStatus": $('#accountStatus').val(),//账号状态
                "phone": $('#phone').val(),//联系电话
                "qqno": $('#qqno').val(),//联系QQ
                "wechatNo": $('#wechatNo').val(),//联系微信
                "storeName": $('#storeName').val(),//店铺名字
                "starttime": $('#starttime').val(),
                "endtime": $('#endtime').val(),
        	};
        };
		function doSearch(refresh){
			var table = $('#table').DataTable({
		        "processing": true,
		        "serverSide": true,
		        "bLengthChange": false,
		        "bFilter": false,
		        "bSort":false,
		        "bDestroy":true,
		        "scrollX": true,
		        "language": {
		            "url": path+"/static/language_datatables.json"
		        },
		        "ajax": {
		            "url": path+"/user/getBusinessUsersList",
		            "type": "POST",
		            "data": getParams()
		        },
		        "oSearch":{
		        	
		        },
		        "columns": [
		            { "data": "businessUserId" ,"width": "10%"},
		            { "data": "userName" ,"width": "10%"},
		            { "data": "registrationTime","width": "20%" },
		            { "data": "phone" ,"width": "10%"},
		            { "data": "qqno" ,"width": "10%"},
		            { "data": "wechatNo" ,"width": "10%"},
		            { "data": "accountStatus","width": "10%"},
		            { "data": "businessUserId","width": "20%"}
		        ],
		        "columnDefs": [
	                 
	                 {
	                     "render": function ( data, type, row ) {
	                    	 return dateTimeFormatter(data);
	                     },
	                     "targets": 2
	                 },
	                 {
	                     "render": function ( data, type, row ) {
	                         if(data==0){
	                        	 return '使用中';
	                         }else if(data==1){
	                        	 return '已冻结';
	                         }
	                     },
	                     "targets": 6
	                 },
	                 {
	                     "render": function ( data, type, row ) {
	                    	var button = '冻结账号';
	                    	if(row.accountStatus==1){
	                    		button = '解冻账号';
	                    	}
	                        var ret= '<button class="btn btn-warning userstatus" key="'+data+'" type="'+row.accountStatus+'">'+button+'</button>&nbsp;'
	                       	ret +='<a class="btn btn-warning" href="'+path+'/user/businessUserDetail?id='+data+'">查看详情</a>';
	                     	return ret;
	                     },
	                     "targets": 7
	                 }
	             ]

		    });
		};
		doSearch();
		//查询事件
		$('#search').click(function(){
			doSearch();
		});
		
		bandclick();
		
		
		
		function bandclick(){
			$('body').on("click",'.userstatus',function(){
				_t = $(this);
				$.ajax({
					type : "post",
					url : path  + "/user/editStatus",
					cache : false,
					data : {
						id : _t.attr('key'),
						accountStatus : _t.attr('type'),
						_t : new Date().getTime()
					},
					dataType : "json",
					success : function(data) {
						showmessage(data.msg);
						if (data.success) {
							doSearch(true);
						}
					}
				});
			});
		}
		
		//导出
		$('#report').click(function(){
			$('#searchForm').attr("action",path+"/user/reportBusiness");
			$('#searchForm').submit();
			$('#searchForm').attr("action","");
		});
	});
	
	
	
	//显示消息
	function showmessage(msg,callback){
		$('#message').ucMessage({
			msg:msg,
			callback:callback
		});
	}
	 
	</script>
</body>
</html>